<?php

class Ext_Model_Role extends Ext_Db_Table
{

    protected $_name = 'sys_role';

    protected $_primary = 'role_id';

    protected $_sequence = 'sys_role_seq';

    protected $_referenceMap = array( 
		'Acls' => array( 
			'columns' => array(	'role_id' ), 
			'refTableClass' => 'Ext_Model_Acl', 
			'refColumns' => array( 'role_id' ) 
		), 
        'UserRole' => array( 
        	'columns' => array( 'role_id' ), 
			'refTableClass' => 'Ext_Model_UserRole', 
            'refColumns' => array( 'role_id' ) 
		), 
        'AclRule' => array( 
        	'columns' => array( 'role_id' ), 
			'refTableClass' => 'Ext_Model_AclRule', 
			'refColumns' => array( 'role_id' ) 
		), 
        'Role' => array( 
        	'columns' => array( 'role_id' ),
			'refTableClass' => 'Ext_Model_Role', 
			'refColumns' => array( 'parent_role_id' ) 
		) 
    );

    public function getRoleId( $roleName )
    {
        $select = $this->select()->where( 'name = ?', $roleName );
        $result = $this->fetchRow( $select );
        if ( empty( $result ) ) {
            return null;
        }
        return $result->role_id;
    }
}

